package in.cent.server.communication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client
{
	private Socket sock;

	public Client(Socket sock)
	{
		this.sock = sock;

		new Thread()
		{
			public void run()
			{
				commThread();
			}
		}.start();
	}

	private void commThread()
	{
		try
		{
			PrintWriter out = new PrintWriter(sock.getOutputStream(), true);

			BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));

			int type;
			String text;
			while ((text = in.readLine()) != null)
			{
				type = Integer.parseInt(text);
				text = in.readLine();
				if (text == null)
					break;
				
				System.out.println("Type:" + type + " Text:" + text);
				// process text here
			}

			out.close();
			in.close();
			sock.close();

		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}

}
